package com.foolishbird.sdk.ui.fragment;

import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.foolishbird.sdk.params.bean.FloatUserInfo;
import com.foolishbird.sdk.ui.assist.OnFinishActivityListener;
import com.foolishbird.sdk.utils.MyFragmentManger;
import com.foolishbird.sdk.utils.ResUtils;


public class FloatChangePwdChooseFragment extends BaseHttpFragment implements View.OnClickListener {


//    private LinearLayout phoneLayout,realnameLayout,versionLayout,pwdLayout;
    private TextView titleTxt;
    private ImageView backView;
    LinearLayout pwdLayout,phoneLayout;

    public static final FloatChangePwdChooseFragment newInstance(Bundle bundle) {
        FloatChangePwdChooseFragment fragment = new FloatChangePwdChooseFragment();
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        int resource = ResUtils.getLayoutIdentifier(getActivity(), "fb_fragment_float_changepwdtype");
        View contentView =inflater.inflate(resource,null);
        titleTxt = contentView.findViewById(getViewIdentifier("fb_fragment_float_title"));
        titleTxt.setText("修改密码");
        backView = contentView.findViewById(getViewIdentifier("fb_fragment_login_back"));
        backView.setOnClickListener(this);
        pwdLayout = contentView.findViewById(getViewIdentifier("float_changepwd_pwd"));
        pwdLayout.setOnClickListener(this);
        phoneLayout = contentView.findViewById(getViewIdentifier("float_changepwd_phone"));
        phoneLayout.setOnClickListener(this);
        userInfo = (FloatUserInfo)getArguments().getSerializable("userInfo");
        return contentView;

    }

    private FloatUserInfo userInfo;



    @Override
    public void onClick(View view) {
        if(view == backView){
//            if(userInfo!=null&&!TextUtils.isEmpty(userInfo.getId_number())){
//
//            }
            MyFragmentManger.getInstance().goBack(this);
//            onba
        }else if(view == pwdLayout){
            MyFragmentManger.getInstance().gotoFragment(FloatChangePwdPwdFragment.newInstance(null));
        }else if(view == phoneLayout){
            if(userInfo!=null&& !TextUtils.isEmpty(userInfo.getPhone())){
                Bundle bundle =new Bundle();
                bundle.putSerializable("phone",userInfo.getPhone());
                MyFragmentManger.getInstance().gotoFragment(FloatChangePwdPhoneFragment.newInstance(bundle));
            }else {
                Toast.makeText(getContext(),"您还没有绑定手机号",Toast.LENGTH_SHORT).show();
            }
        }

//        OnFinishActivityListener listener = getOnFinishActivityListener();
//        if (listener != null) {
//            listener.doFinishActivity(this);
//        }
    }

    private OnFinishActivityListener getOnFinishActivityListener() {
        if (!isNullContext()) {
            Activity activity = getActivity();
            if (activity instanceof OnFinishActivityListener) {
                return (OnFinishActivityListener) activity;
            }
        }
        return null;
    }
}
